﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.Configuration;
using OgilvyOne.UKNow.Mobile.Model.Events;
using OgilvyOne.UKNow.Mobile.APIs;

namespace OgilvyOne.UKNow.Mobile.Utilities
{
    public class ModelConvertUtility
    {
        public static EventInfo ToEventInfo(EventsModel em, bool outputDetail)
        {
            EventInfo elac = new EventInfo();
            elac.Eventid = em.ID.ToString();
            elac.Comment_count = em.CommentsNum.ToString();
            elac.Artname = em.ArtForm.Name;
            elac.Checkin_count = em.CheckInNum.ToString();
            elac.City = em.CityModel != null ? em.CityModel.Cnname : "";
            elac.Desc = "";
            if (outputDetail)
                elac.Desc = em.PhoneDetail;
            elac.Favorite_count = em.FavoriteNum;
            elac.Isfeature = em.IsSpecial == 1 ? "是" : "否";
            if (!string.IsNullOrEmpty(elac.Topimg))
            {
                elac.Topimg = ConfigCacheManager.DomainName +
                              ConfigCacheManager.FilePath.GetFrontImageVirtualPath(elac.Topimg);
            }
            elac.Topimg = em.TopImg;
            elac.Up_count = em.PraiseNum.ToString();
            elac.Subtitle = em.SubTitle;
            elac.Venue = em.Venue;
            elac.map_venue = string.IsNullOrEmpty(em.PhoneVenue) ? em.Venue : em.PhoneVenue;
            elac.Url = em.TicketUrl;
            elac.Title = em.EventPhone;
            elac.Sponsor = em.Sponsor != null ? em.Sponsor.Name : "";
            elac.Listimg = "";
            elac.Longitude = em.Lng;
            elac.Latitude = em.Lat;

            List<PhoneImage> phoneImages = new List<PhoneImage>();
            if (em.PhoneImagesList != null && em.PhoneImagesList.Count > 0)
            {
                foreach (PhoneImage model in em.PhoneImagesList)
                {
                    PhoneImage mImage = new PhoneImage();
                    mImage.Imagename = model.Imagename;
                    if (!string.IsNullOrEmpty(model.Imagpath))
                    {
                        mImage.Imagpath = ConfigCacheManager.DomainName +
                                          ConfigCacheManager.FilePath.GetImageVirtualPath(model.Imagpath);
                    }
                    else
                    {
                        mImage.Imagpath = "";

                    }
                    if (!string.IsNullOrEmpty(model.Thumbpath))
                    {

                        mImage.Thumbpath = ConfigCacheManager.DomainName +
                                           ConfigCacheManager.FilePath.GetImageVirtualPath(model.Thumbpath);
                    }
                    else
                    {
                        mImage.Thumbpath = "";
                    }
                    phoneImages.Add(mImage);

                }
            }
            elac.Images = phoneImages;
            //APIComm acm = new APIComm();
            //elac.Images = acm.DirToLisO(em.PhoneImages);

            if (!string.IsNullOrEmpty(em.ListImg))
                elac.Listimg = ConfigCacheManager.DomainName + ConfigCacheManager.FilePath.UploadImagePath.VirtualPath + "/" + em.ListImg;
            elac.Showtime = em.ShowTime;
            return elac;
        }


        public static  List<PhoneImage> GetNewPhoneImages(int? nid)
        {
            NewsBLL bll = new NewsBLL(2052);
            List<PhoneImage> listimage = new List<PhoneImage>();
            IList<PhoneImage> mList = bll.GetNewsPhone(nid);
            if (mList != null && mList.Count > 0)
            {
                foreach (var phoneImage in mList)
                {
                    PhoneImage mImage = new PhoneImage();
                    mImage.Imagename = phoneImage.Imagename;
                    if (!string.IsNullOrEmpty(phoneImage.Imagpath))
                    {

                        mImage.Imagpath = ConfigCacheManager.DomainName +
                                          ConfigCacheManager.FilePath.GetImageVirtualPath(phoneImage.Imagpath);
                    }
                    else
                    {
                        mImage.Imagpath = "";

                    }
                    mImage.Thumbpath = !string.IsNullOrEmpty(phoneImage.Thumbpath)
                                           ? ConfigCacheManager.DomainName +
                                             ConfigCacheManager.FilePath.GetImageVirtualPath(phoneImage.Thumbpath)
                                           : "";
                    listimage.Add(mImage);


                }
            }
            return listimage;
        }


    }
}
